import { defineConfig } from '@croco/vite-config';

import AutoImport from 'unplugin-auto-import/vite';
import ElementPlus from 'unplugin-element-plus/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';

export default defineConfig(async () => {
    return {
        application: {},
        vite: {
            plugins: [
                AutoImport({
                    resolvers: [ElementPlusResolver()],
                    imports: ['vue', 'vue-router'], // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
                    dts: 'src/types/auto-imports.d.ts',
                }),
                Components({
                    resolvers: [ElementPlusResolver()],
                    dts: 'src/types/components.d.ts',
                    dirs: ['src/components'], // 自动注册项目本地组件
                }),
                ElementPlus({
                    format: 'esm',
                }),
            ],
            server: {
                proxy: {
                    '/api': {
                        changeOrigin: true,
                        rewrite: (path) => path.replace(/^\/api/, ''),
                        // mock代理目标地址
                        target: 'http://localhost:5320/api',
                        ws: true,
                    },
                },
            },
        },
    };
});
